package com.kjlink.internal.workreport.helper;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.stream.Stream;

/**
 * 描述:
 *
 * @author Vic.xu
 * @since 2024-04-30 11:24
 */
public class PasswordHelper {

    /**
     * 密码加密方式保持和OA一致
     * modification
     * - 2024-12-11  oa login修改为 前端小写md5
     */
    public static String encryptPassword(String plainPassword) {
        return DigestUtils.md5Hex(plainPassword).toUpperCase();
    }

    /**
     * 验证密码
     *
     * @param plainPassword 明文密码
     * @param password      密文密码
     * @return 验证成功返回true
     */
    public static boolean validatePassword(String plainPassword, String password) {
        String encrypted = encryptPassword(plainPassword);
        return StringUtils.equalsIgnoreCase(encrypted, password);
    }

    public static void main(String[] args) {
        generate();
    }


    public static void generate() {
        /*
        xiabt:D419AFEA29B3E21595FB0BBB457A8E86
        changhb:D613E8EABED2272C6FF473AD68B0D9EE
        zhangyang:EA49A359A86056C272C2A8345D93C4BE

         */
        // ab49088efd77e5985e343d0aff0d1da7

        String password = "202341";
        String s = encryptPassword(password);
        System.out.println(s);

        Stream.of("xiabt", "changhb", "zhangyang").forEach(userCode -> {
            System.out.println(userCode + ":" + encryptPassword(userCode));
        });

    }
}